/*
 * @Author: underMoonzs 1994186472@qq.com
 * @Date: 2025-10-05 21:41:58
 * @LastEditors: underMoonzs 1994186472@qq.com
 * @LastEditTime: 2025-10-06 16:01:30
 * @FilePath: \environment-map-app\vite.config.js
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
import { defineConfig, loadEnv } from 'vite'
import vue from '@vitejs/plugin-vue'
import path from 'path'
const baseUrl ='http://39.106.226.59:9527'
// https://vitejs.dev/config/
export default defineConfig(({ mode }) => {
  // 加载环境变量
  const env = loadEnv(mode, process.cwd(), '')
  
  return {
    plugins: [vue()],
    
    // 配置路径别名
    resolve: {
      alias: {
        '@': path.resolve(__dirname, 'src'),
        '~': path.resolve(__dirname, ''),
      }
    },
    
    // 开发服务器配置
    server: {
      host: '0.0.0.0',
      port: env.VITE_PORT || 3000,
      open: true,
      proxy: {
        // 代理配置
        '/api': {
          target: baseUrl,
          changeOrigin: true,
          rewrite: (path) => path.replace(/^\/prod-api/, '')
        }
      }
    },
    
    // 构建配置
    build: {
      outDir: 'dist',
      assetsDir: 'static',
      rollupOptions: {
        output: {
          chunkFileNames: 'static/js/[name]-[hash].js',
          entryFileNames: 'static/js/[name]-[hash].js',
          assetFileNames: 'static/[ext]/[name]-[hash].[ext]'
        }
      }
    },
    
    // 环境变量配置
    define: {
      __APP_ENV__: JSON.stringify(env)
    },
    
    // CSS 配置
    css: {
      preprocessorOptions: {
        scss: {
          additionalData: `@import "@/styles/variables.scss";`
        }
      }
    }
  }
})